<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/meta.jsp"%>
<link href="<s:url value='/css/main.css'/>" rel="stylesheet"
	type="text/css" />
<link rel="stylesheet"
	href="<s:url value='/js/jquery/plugins/jquery-treeview/jquery.treeview.css'/>" type="text/css" />
<script type="text/javascript" language="JavaScript"
	src="<s:url value='/js/jquery/jquery-1.3.2.min.js'/>"></script>
<script type="text/javascript" language="JavaScript"
	src="<s:url value='/js/jquery/plugins/jquery-treeview/jquery.treeview.js'/>"></script>
<script type="text/javascript"
	src="<s:url value='/js/DatePicker/DatePicker.js'/>"></script>
<script type="text/javascript">
	function setCategory(obj, treeId){
		$("input[name='item.categoryId']")[0].value = obj.getAttribute("tvalue");
		var xxs = $("#"+treeId).find("a");
		for(i=0; i<xxs.length; i++){
			xxs[i].style.backgroundColor = "";
		}
		obj.style.backgroundColor = "lightblue";
	}

	$(function(){
		$("#categoryTree").treeview({
			persist: "location",
			collapsed: false,
			unique: true
		});

		var parentId = $("input[name='item.categoryId']")[0].value;
		var xxs = $("#categoryTree").find("a");
		for(i=0; i<xxs.length; i++){
			if(xxs[i].getAttribute("tvalue") == parentId) {
				xxs[i].style.backgroundColor = "lightblue";
			}
		}

		$("form")[0].onsubmit = function(){
			var msg = "";
			if($("textarea[name='item.description']")[0].value.length > 120){
				msg += "文件描述不能超过120字符\n";
			}
			if($("input[name='item.categoryId']")[0].value == ""){
				msg += "请选择一个分类!";
			}
			if(msg != ""){
				alert(msg);
				return false;
			}
		}
	});
</script>
<title>上传资源</title>
</head>
<body>
<s:if test="%{message != null}">
	<font color="red"><s:property value="message" escape="false" /></font>
</s:if>
<s:if test="%{actionErrors != null}">
	<s:iterator value="actionErrors" status="stat">
		<s:iterator value="value" status="stat">
			<font color="red"><s:property value="value.get(#stat.index)" /></font><br/>
		</s:iterator>
	</s:iterator>
</s:if>
<s:if test="%{fieldErrors != null}">
	<s:iterator value="fieldErrors" status="stat">
		<s:iterator value="value" status="stat">
			<font color="red"><s:property value="value.get(#stat.index)" /></font><br/>
		</s:iterator>
	</s:iterator>
</s:if>
<br />
<s:form action="FileUploadSave" namespace="/" method="post" enctype="multipart/form-data">
	<table width="100%" border="0" cellpadding="3" cellspacing="1"
		bgcolor="#E2E2E2">
		<tr class="tr1">
			<td colspan="2">上传文件</td>
		</tr>
		<tr class="tab">
			<td class="td1">选择文件(20M以内)：<font color="red">*</font></td>
			<td><s:file name="upload"></s:file></td>
		</tr>
		<tr class="tab">
			<td class="td1">文件名(不填写将使用上传文件的文件名)：</td>
			<td><s:textfield name="item.fileName" size="20"></s:textfield></td>
		</tr>
		<tr class="tab">
			<td class="td1">文件描述：</td>
			<td><s:textarea name="item.description" cols="50" rows="5"></s:textarea></td>
		</tr>
		<tr class="tab">
			<td class="td1">分类：</td>
			<td>
				<s:hidden name="item.categoryId"></s:hidden>
				<s:hidden name="treeString"></s:hidden>
				<s:property value="treeString" escape="false" />
			</td>
		</tr>
		<tr class="tab">
			<td colspan="2"><s:submit cssClass="button" value="提交"></s:submit></td>
		</tr>
	</table>
</s:form>
<br />
</body>
</html>